PhD

The LaTeX sources of my Ph.D. thesis
git clone https://esimon.eu/repos/PhD.git
Log | Files | Refs | README | LICENSE

terminal color.lua (1606B)


      1 local tcolor = {}
      2 
      3 function tcolor.warning(msg)
      4 	io.stdout:write("\27[38:5:208;1m" .. tostring(msg) .. "\27[0m")
      5 end
      6 
      7 function start_page_number()
      8 	io.stdout:write("\27[33;1m[")
      9 	local j = 9
     10 	while tex.count[j] == 0 and j > 0 do
     11 		j = j - 1
     12 	end
     13 	for k=0, j do
     14 		io.stdout:write(tex.count[k])
     15 		if k < j then
     16 			io.stdout:write(".")
     17 		end
     18 	end
     19 	io.stdout:write("\27[0m")
     20 end
     21 function stop_page_number()
     22 	io.stdout:write("\27[33;1m]\27[0m")
     23 end
     24 
     25 local stack = {}
     26 
     27 function is_local_file(filename)
     28 	if filename:sub(1, 2) == "./" then
     29 		return true
     30 	end
     31 	if filename:sub(1, 3) == "\"./" then
     32 		return true
     33 	end
     34 	return false
     35 end
     36 
     37 local filetypes_left = { [0]="?", "(", "{", "<", "<", "<<" }
     38 local filetypes_right = { [0]="?", ")", "}", ">", ">", ">>" }
     39 
     40 function start_file(category, filename)
     41 	if category == 1 and is_local_file(filename) then
     42 		io.stdout:write("\27[90;1m")
     43 		table.insert(stack, true)
     44 	else
     45 		io.stdout:write("\27[90m")
     46 		table.insert(stack, false)
     47 	end
     48 	io.stdout:write(filetypes_left[category]..filename.."\27[0m")
     49 end
     50 
     51 function stop_file(category)
     52 	local t = table.remove(stack)
     53 	if t then
     54 		io.stdout:write("\27[90;1m")
     55 	elseif t == false then
     56 		io.stdout:write("\27[90m")
     57 	end
     58 	io.stdout:write(filetypes_right[category] .. "\27[0m")
     59 end
     60 
     61 luatexbase.add_to_callback("start_page_number", start_page_number, "Start yellow page number.")
     62 luatexbase.add_to_callback("stop_page_number", stop_page_number, "Stop yellow page number.")
     63 luatexbase.add_to_callback("start_file", start_file, "Start grey file.")
     64 luatexbase.add_to_callback("stop_file", stop_file, "Stop grep file.")
     65 
     66 return tcolor